<template>
  <div class="body">
    <div class="container">
      <div class="content">
        <span class="folder logo">
          <img src="../style/img/folder.png" alt="">
        </span>
        <div class="upload-input">
          <input
                type="file"
                id="structure"
                class="fileUp"
                ref="structure"
                @change="uploadStructure"
              >
        </div>
        <span class="btn-add">
          點擊添加PDF文檔
        </span>
        <span class="pdf-logo logo">
          <img src="../style/img/pdf-logo.png" alt="">
        </span>
      </div>
    </div>
  </div>
</template>

<script>
import axios from 'axios'
export default {
  name: 'UploadStructure',
  data () {
    return {
      // key: value
    }
  },
  methods: {
    uploadStructure () {
      var structure = this.$refs.structure
      this.upload(structure, 'file', 'structure', '/think.php/system/file/upload')
    },
    upload (file, fileType, type, url) {
      const image = new FormData()
      image.append(fileType, file.files[0])
      image.append('type', type)
      axios.post(url, image, {
        headers: {
          'Content-Type': 'multipart/form-data'
        }
      }).then(res => {
        if (res.data.code === 1) {
          alert('上传成功')
          // this.loadStore()
        }
      })
        .catch(err => {
          console.log(err)
        })
    }
  }
}
</script>

<style scoped>
* {
  margin:0;
  padding: 0;
}
.body {
  position: relative;
  min-height: 800px;
  height: auto;
  background: #fff;
}
.upload-input {
  float: left;
  width: 300px;
  height: 63px;
  border: 1px solid #000;
  position: absolute;
  z-index: 999;
  top: 10px;
  left: 15%;
  opacity: 0; /*css属性——opcity不透明度，取值0-1*/
}
.fileUp {
  display: inline-block;
  width: 200px;
  padding-left: 30px;
}
.container {
  width: 100%;
  height:83px;
  background: url(../style/img/16.png);
  padding: 8px;
  /* padding-bottom: 8px; */
}
.content {
  width: 98%;
  height: 63px;
  line-height: 63px;
  margin: 0 auto;
  background: #fff;
  border-radius: 18px;
}
.btn-add {
  font-size: 19px;
  color: rgba(0, 0, 0, 0.58);
  margin-left: 10px;
}
.folder img {
  width: 23px;
  height: 23px;
  margin-left: 20px;
  margin-bottom: 3px;
}
.pdf-logo img{
  width: 38px;
  height: 38px;
  float: right;
  margin-top: 16px;
  margin-right: 20px;
}
</style>
